<template>
  <div class="content">
    <ul class="mui-table-view">
      <li class="mui-table-view-cell mui-media" v-for='item in newsList' :key='item.id'>
        <router-link :to="'/home/newsInfo/'+item.id" >
          <img
            class="mui-media-object mui-pull-left"
            :src="item.img || defaultImg" 
          />
          <div class="mui-media-body">
            <h1>{{item.title}}</h1>
            <p class="mui-ellipsis">
              <span>发表时间：{{item.pubDate}}</span>
              <span>来源：{{item.source}}</span>
            </p>
          </div>
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import axios from "axios"
import { Toast } from 'mint-ui'
export default {
  data() {
    return {
        newsList:[],
        defaultImg:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1565356494113&di=6b978b88f7905dea81571f3fecb5a16d&imgtype=0&src=http%3A%2F%2Fupload.chinaz.com%2F2018%2F0906%2F201809061420356296.jpg'
    };
  },
  created() {
    this.getNews();
  },
  methods: {
    getNews() {
      axios.get("http://route.showapi.com/109-35", {
        params: {
          showapi_appid: "69119",
          showapi_sign: "2f25c88c51774595b0b8ea8b17852294"
        }
      })
        .then(res=>{
            if(res.data.showapi_res_code ===0 ){
                this.newsList=res.data.showapi_res_body.pagebean.contentlist
            }else{
                Toast('新闻列表获取失败')
            }
        })
    }
  }
};
</script>

<style lang="scss" scoped>
.content{
    overflow-x: hidden;
}
.mui-table-view {
  li {
    h1 {
      font-size: 14px;
    }
    .mui-ellipsis {
      font-size: 12px;
      color: royalblue;
      display: flex;
      justify-content: space-between;
    }
  }
}
</style>
